package com.cn.wanxi.servlet;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ImgModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.util.ToolFileUpload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/upload")
public class FileUploadServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String path = ToolFileUpload.upload(req, resp);
        ImgModel imgModel = new ImgModel();
        imgModel.setSrc(path);
        resp.getWriter().println(JSONObject.toJSONString(ResultModel.getResultModel(imgModel)));
    }


}
